<?php

namespace app\admin\service;

use app\admin\model\Supplier as SupplierMdl;

use think\Db;
use think\Exception;

class Supplier
{

    /**
     * 导出数据
     */
    public static function export($request){
        $param = $request->param();

        $where = [
            'status' => 1,
        ];

        $model = new SupplierMdl();
        $data = $model->where($where)->select();
        if(count($data) <= 0){
            return [
                'code' => 2,
                'msg' => '没有数据！'
            ];
        }

        $cellName = array(
            'A' => ['id', '序号'],
            'B' => ['name', '供货商名称'],
            'C' => ['office_phone', '办公电话'],
            'D' => ['fax', '传真'],
            'E' => ['address', '地址'],
            'F' => ['contacts', '联系人'],
            'G' => ['phone', '手机号'],
        );

        $filePath = ROOT_PATH . 'public' . DS . 'upload' . DS . 'csv' . DS . 'supplier' . DS . date('Y-m-d');
        $fileName = $filePath . '/supplier_' . date('y-m-d-H-i-s');

        $excel = new Excel();
        $excel::exportExcel('供货商', $data, $cellName, $filePath, $fileName);

        return [
            'code' => 1,
            'msg' => '导出成功！'
        ];
    }

}